//index.js
//获取应用实例
const app = getApp()

Page({
    data: {
		totalPrice: 0,
		productBaseUrl: '',
		paymentProductData: [],
		addressData: {},
		showAddress: false,
		popup: false
    },
	getAddress: function () {
		var that = this;
		wx.chooseAddress({
			success: function (res) {
				that.setData({
					addressData: res,
					showAddress: true
				})
			}
		})
		console.log('getAddress', this.data)
	},
    //事件处理函数
	payment: function(e) {
		wx.requestPayment({
			'timeStamp': '1490840662',
			'nonceStr': '5K8264ILTKCH16CQ2502SI8ZNMTM67VS',
			'package': 'prepay_id=wx2017033010242291fcfe0db70013231072',
			'signType': 'MD5',
			'paySign': '9A0A8659F005D6984697E2CA0A9CF3B7',
			'success':function(res){
				console.log('payment', res)
			},
			'fail':function(res){
				console.log('payment fail', res)
			}
		})
		// if(this.data.addressData) {
		// 	this.setData({
		// 		popup: true
		// 	})
		//
		// 	this.setData({
		// 		popup: false
		// 	})
		//
		// } else {
        	// this.setData({
		// 		popup: true
		// 	})
		// }
    },
    onLoad: function () {

		var that = this;
		wx.getStorage({
			key: 'paymentList',
			success: function(res) {
				console.log('paymentList',res.data)
				that.setData({
					productBaseUrl: app.globalData.productBaseUrl,
					paymentProductData : Object.values(res.data.productList),
					totalPrice: res.data.payTotalPrice
				})
			}
		})
		wx.setNavigationBarTitle({
			title: 'Payment'
		});
    },
	onHide: function() {
		console.log('onHide')
    },

	onLaunch: function () {
        console.log('onlaunch')
	},
	onShow: function() {
    },

	onUnlaunch: function() {
		console.log('onUnlaunch')
    },

	userInfoReadyCallback: function() {
		console.log('userInfoReadyCallback')
    },

    // getUserInfo: function(e) {
    //     app.globalData.userInfo = e.detail.userInfo
    //     this.setData({
    //         userInfo: e.detail.userInfo,
    //         hasUserInfo: true
    //     })
    // }
})
